<!--
 * @Descripttion:
 * @Author: chendingfengmail@163.com
 * @version:
 * @Date: 2021-06-10 14:40:56
 * @LastEditors: chendingfengmail@163.com
 * @LastEditTime: 2022-01-17 13:58:10
-->
<template>
  <el-dialog
    title="重置用户密码"
    width="30%"
    top="30vh"
    center
    :visible.sync="visible"
    :before-close="modalClose"
    :close-on-click-modal="false"
    >
    <el-form :rules="resetRules" ref="resetForm" :model="modelData">
      <el-form-item label="重置密码"  prop="password" label-width="80px">
        <el-input
          v-model="modelData.password"
          autocomplete="off"
          maxlength="30"
          placeholder="请输入重置密码"
          show-password
        ></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button type="primary" @click="formSubmit" :loading="loading">提 交</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'resetPasswordDialog',
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    modelData: {
      type: Object,
      default: () => {
        return {
          id:'',
          password:''
        };
      },
    },
  },
  data() {
    return {
      // formLabelWidth: '100px',
      loading: false,
      resetRules: {
        password: this.$Validate.password(true, '请输入重置密码'),
      },
    };
  },
  methods: {
    // 表单提交
    formSubmit() {
      console.log("submit")
      this.$refs.resetForm.validate((valid) => {
        if (valid) {
          this.loading = true;
          let param = {
            id: this.modelData.id,
            password: this.modelData.password,
          };
          this.$api.user
            .resetPassword(param)
            .then((res) => {
              this.$message.success('重置密码成功');
              this.loading = false;
              this.modalClose();
            })
            .catch((error) => {
              console.log(error);
              this.loading = false;
            });
        }
      });
    },
    // 重置表单
    resetForm() {
      this.$nextTick(() => {
        this.$refs.resetForm.resetFields();
      });
    },
    // 对话框关闭
    modalClose() {
      this.resetForm();
      this.$emit('update:visible', false); // 直接修改父组件的属性
    },
  },
};
</script>
<style lang="scss">
</style>
